home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / inetutil.1 / inetutil / inetutils-1.1 / telnetd / defs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-27  |  8.3 KB  |  305 lines

  1. /*
  2.  * Copyright (c) 1989, 1993
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)defs.h    8.1 (Berkeley) 6/4/93
  34.  */
  35.  
  36. /*
  37.  * Telnet server defines
  38.  */
  39. #include <sys/types.h>
  40. #include <sys/param.h>
  41.  
  42. #ifndef    BSD
  43. # define    BSD 43
  44. #endif
  45.  
  46. #ifdef HAVE_TERMIOS_H
  47. #define USE_TERMIO
  48. #else  /* !HAVE_TERMIOS_H */
  49. #ifdef HAVE_TERMIO_H
  50. #define USE_TERMIO
  51. #define SYSV_TERMIO
  52. #endif
  53. #endif /* HAVE_TERMIOS_H */
  54.  
  55. #if    defined(CRAY) && !defined(LINEMODE)
  56. # define SYSV_TERMIO
  57. # define LINEMODE
  58. # define KLUDGELINEMODE
  59. # define DIAGNOSTICS
  60. # if defined(UNICOS50) && !defined(UNICOS5)
  61. #  define UNICOS5
  62. # endif
  63. # if !defined(UNICOS5)
  64. #  define BFTPDAEMON
  65. #  define HAS_IP_TOS
  66. # endif
  67. #endif /* CRAY */
  68. #if defined(UNICOS5) && !defined(NO_SETSID)
  69. # define NO_SETSID
  70. #endif
  71.  
  72. #if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
  73. #define TELOPTS
  74. #define TELCMDS
  75. #define    SLC_NAMES
  76. #endif
  77.  
  78. #if    defined(SYSV_TERMIO) && !defined(USE_TERMIO)
  79. # define    USE_TERMIO
  80. #endif
  81.  
  82. #include <sys/socket.h>
  83. #ifndef    CRAY
  84. #include <sys/wait.h>
  85. #endif    /* CRAY */
  86. #include <fcntl.h>
  87. #include <sys/file.h>
  88. #include <sys/stat.h>
  89. #include <sys/time.h>
  90. #ifndef    FILIO_H
  91. #include <sys/ioctl.h>
  92. #else
  93. #include <sys/filio.h>
  94. #endif
  95.  
  96. #include <netinet/in.h>
  97.  
  98. #include <arpa/telnet.h>
  99.  
  100. #include <stdio.h>
  101. #ifdef    __STDC__
  102. #include <stdlib.h>
  103. #endif
  104. #include <signal.h>
  105. #include <errno.h>
  106. #include <netdb.h>
  107. #include <syslog.h>
  108. #ifndef    LOG_DAEMON
  109. #define    LOG_DAEMON    0
  110. #endif
  111. #ifndef    LOG_ODELAY
  112. #define    LOG_ODELAY    0
  113. #endif
  114. #include <ctype.h>
  115. #ifndef NO_STRING_H
  116. #include <string.h>
  117. #else
  118. #include <strings.h>
  119. #endif
  120.  
  121. #ifndef    USE_TERMIO
  122. #include <sgtty.h>
  123. #else
  124. # ifdef    SYSV_TERMIO
  125. # include <termio.h>
  126. # else
  127. # include <termios.h>
  128. # endif
  129. #endif
  130. #if !defined(USE_TERMIO) || defined(NO_CC_T)
  131. typedef unsigned char cc_t;
  132. #endif
  133.  
  134. #ifdef    __STDC__
  135. #include <unistd.h>
  136. #endif
  137.  
  138. #ifndef _POSIX_VDISABLE
  139. # ifdef VDISABLE
  140. #  define _POSIX_VDISABLE VDISABLE
  141. # else
  142. #  define _POSIX_VDISABLE ((unsigned char)'\377')
  143. # endif
  144. #endif
  145.  
  146. #ifdef    CRAY
  147. # ifdef    CRAY1
  148. # include <sys/pty.h>
  149. #  ifndef FD_ZERO
  150. # include <sys/select.h>
  151. #  endif /* FD_ZERO */
  152. # endif    /* CRAY1 */
  153.  
  154. #include <memory.h>
  155. #endif    /* CRAY */
  156.  
  157. #ifdef __hpux
  158. #include <sys/ptyio.h>
  159. #endif
  160.  
  161. #if    !defined(TIOCSCTTY) && defined(TCSETCTTY)
  162. # define    TIOCSCTTY TCSETCTTY
  163. #endif
  164.  
  165. #ifndef    FD_SET
  166. #ifndef    HAVE_fd_set
  167. typedef struct fd_set { int fds_bits[1]; } fd_set;
  168. #endif
  169.  
  170. #define    FD_SET(n, p)    ((p)->fds_bits[0] |= (1<<(n)))
  171. #define    FD_CLR(n, p)    ((p)->fds_bits[0] &= ~(1<<(n)))
  172. #define    FD_ISSET(n, p)    ((p)->fds_bits[0] & (1<<(n)))
  173. #define FD_ZERO(p)    ((p)->fds_bits[0] = 0)
  174. #endif    /* FD_SET */
  175.  
  176. /*
  177.  * I/O data buffers defines
  178.  */
  179. #define    NETSLOP    64
  180. #ifdef CRAY
  181. #undef BUFSIZ
  182. #define BUFSIZ  2048
  183. #endif
  184.  
  185. #define    NIACCUM(c)    {   *netip++ = c; \
  186.                 ncc++; \
  187.             }
  188.  
  189. /* clock manipulations */
  190. #define    settimer(x)    (clocks.x = ++clocks.system)
  191. #define    sequenceIs(x,y)    (clocks.x < clocks.y)
  192.  
  193. /*
  194.  * Linemode support states, in decreasing order of importance
  195.  */
  196. #define REAL_LINEMODE    0x04
  197. #define KLUDGE_OK    0x03
  198. #define    NO_AUTOKLUDGE    0x02
  199. #define KLUDGE_LINEMODE    0x01
  200. #define NO_LINEMODE    0x00
  201.  
  202. /*
  203.  * Structures of information for each special character function.
  204.  */
  205. typedef struct {
  206.     unsigned char    flag;        /* the flags for this function */
  207.     cc_t        val;        /* the value of the special character */
  208. } slcent, *Slcent;
  209.  
  210. typedef struct {
  211.     slcent        defset;        /* the default settings */
  212.     slcent        current;    /* the current settings */
  213.     cc_t        *sptr;        /* a pointer to the char in */
  214.                     /* system data structures */
  215. } slcfun, *Slcfun;
  216.  
  217. #ifdef DIAGNOSTICS
  218. /*
  219.  * Diagnostics capabilities
  220.  */
  221. #define    TD_REPORT    0x01    /* Report operations to client */
  222. #define TD_EXERCISE    0x02    /* Exercise client's implementation */
  223. #define TD_NETDATA    0x04    /* Display received data stream */
  224. #define TD_PTYDATA    0x08    /* Display data passed to pty */
  225. #define    TD_OPTIONS    0x10    /* Report just telnet options */
  226. #endif /* DIAGNOSTICS */
  227.  
  228. /*
  229.  * We keep track of each side of the option negotiation.
  230.  */
  231.  
  232. #define    MY_STATE_WILL        0x01
  233. #define    MY_WANT_STATE_WILL    0x02
  234. #define    MY_STATE_DO        0x04
  235. #define    MY_WANT_STATE_DO    0x08
  236.  
  237. /*
  238.  * Macros to check the current state of things
  239.  */
  240.  
  241. #define    my_state_is_do(opt)        (options[opt]&MY_STATE_DO)
  242. #define    my_state_is_will(opt)        (options[opt]&MY_STATE_WILL)
  243. #define my_want_state_is_do(opt)    (options[opt]&MY_WANT_STATE_DO)
  244. #define my_want_state_is_will(opt)    (options[opt]&MY_WANT_STATE_WILL)
  245.  
  246. #define    my_state_is_dont(opt)        (!my_state_is_do(opt))
  247. #define    my_state_is_wont(opt)        (!my_state_is_will(opt))
  248. #define my_want_state_is_dont(opt)    (!my_want_state_is_do(opt))
  249. #define my_want_state_is_wont(opt)    (!my_want_state_is_will(opt))
  250.  
  251. #define    set_my_state_do(opt)        (options[opt] |= MY_STATE_DO)
  252. #define    set_my_state_will(opt)        (options[opt] |= MY_STATE_WILL)
  253. #define    set_my_want_state_do(opt)    (options[opt] |= MY_WANT_STATE_DO)
  254. #define    set_my_want_state_will(opt)    (options[opt] |= MY_WANT_STATE_WILL)
  255.  
  256. #define    set_my_state_dont(opt)        (options[opt] &= ~MY_STATE_DO)
  257. #define    set_my_state_wont(opt)        (options[opt] &= ~MY_STATE_WILL)
  258. #define    set_my_want_state_dont(opt)    (options[opt] &= ~MY_WANT_STATE_DO)
  259. #define    set_my_want_state_wont(opt)    (options[opt] &= ~MY_WANT_STATE_WILL)
  260.  
  261. /*
  262.  * Tricky code here.  What we want to know is if the MY_STATE_WILL
  263.  * and MY_WANT_STATE_WILL bits have the same value.  Since the two
  264.  * bits are adjacent, a little arithmatic will show that by adding
  265.  * in the lower bit, the upper bit will be set if the two bits were
  266.  * different, and clear if they were the same.
  267.  */
  268. #define my_will_wont_is_changing(opt) \
  269.             ((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
  270.  
  271. #define my_do_dont_is_changing(opt) \
  272.             ((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
  273.  
  274. /*
  275.  * Make everything symetrical
  276.  */
  277.  
  278. #define    HIS_STATE_WILL            MY_STATE_DO
  279. #define    HIS_WANT_STATE_WILL        MY_WANT_STATE_DO
  280. #define HIS_STATE_DO            MY_STATE_WILL
  281. #define HIS_WANT_STATE_DO        MY_WANT_STATE_WILL
  282.  
  283. #define    his_state_is_do            my_state_is_will
  284. #define    his_state_is_will        my_state_is_do
  285. #define his_want_state_is_do        my_want_state_is_will
  286. #define his_want_state_is_will        my_want_state_is_do
  287.  
  288. #define    his_state_is_dont        my_state_is_wont
  289. #define    his_state_is_wont        my_state_is_dont
  290. #define his_want_state_is_dont        my_want_state_is_wont
  291. #define his_want_state_is_wont        my_want_state_is_dont
  292.  
  293. #define    set_his_state_do        set_my_state_will
  294. #define    set_his_state_will        set_my_state_do
  295. #define    set_his_want_state_do        set_my_want_state_will
  296. #define    set_his_want_state_will        set_my_want_state_do
  297.  
  298. #define    set_his_state_dont        set_my_state_wont
  299. #define    set_his_state_wont        set_my_state_dont
  300. #define    set_his_want_state_dont        set_my_want_state_wont
  301. #define    set_his_want_state_wont        set_my_want_state_dont
  302.  
  303. #define his_will_wont_is_changing    my_do_dont_is_changing
  304. #define his_do_dont_is_changing        my_will_wont_is_changing
  305.